﻿using System;
using SharedLibraries.Constants;
using ThangNM_LIB.FUNC;

namespace ThangNM
{
    public partial class Token : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                Int16 b = 1;
                var a = Convert.ToBoolean(b);
                BindUrl();
                //Convert Int32 => Binary: Convert.ToString(198, 2);
                //Convert Binary => Int32: Convert.ToInt32("11000110", 2);


                Byte bit = Convert.ToByte(12);
                String lstBit = "1101";
                MsgUC1.setNotifications(1, Convert.ToInt32(lstBit, 2).ToString());
                lstBit = Convert.ToString(198, 2);
                MsgUC1.setNotifications(1, lstBit);

                //SQLiteDataProvider.Test();

                //DataTable dt = TopicDAO.SelectItem_new(400017);
                //string strOutput = JsonConvert.SerializeObject(dt);
                //txtUrl.Text = strOutput;     
                //strOutput = strOutput.Substring(1);
                //strOutput = strOutput.Substring(0, strOutput.Length-1);
                //TopicEO objT = new TopicEO();
                //objT = (TopicEO)Commons.Json2Object(strOutput, objT.GetType());
                //MsgUC1.setClearMsg();
                if (!IsPostBack)
                {
                    if (Request.QueryString[QueryString.key] != null)
                    {
                        string sToken = Security.Login.Decrypt(Request.QueryString[QueryString.key].Replace(" ", "+"), System.Configuration.ConfigurationManager.AppSettings["FACEBOOK"]);

                    }
                }
            }
            catch (Exception ex)
            {
                MsgUC1.setNotifications(ConstEx.FunctionSetMsg.ERROR, ex.Message, ex.ToString());
            }
        }

        protected void btnCheckUrl_Click(object sender, EventArgs e)
        {
            try
            {
                Uri tt;
                Uri.TryCreate(txtUrl.Text, UriKind.RelativeOrAbsolute, out tt);
                MsgUC1.setNotifications(ConstEx.FunctionSetMsg.INFO, tt.PathAndQuery.ToString());
                //using (var client = new System.Net.WebClient())
                //using (var stream = client.OpenRead(txtUrl.Text))
                //using (var textReader = new System.IO.StreamReader(stream, System.Text.Encoding.UTF8, true))
                //{
                //    MsgUC1.setNotifications(ConstEx.FunctionSetMsg.INFO, System.Web.HttpUtility.HtmlDecode(textReader.ReadToEnd()));
                //}
            }
            catch (Exception ex)
            {
                MsgUC1.setNotifications(ConstEx.FunctionSetMsg.ERROR, ex.Message, ex.ToString());
            }
        }

        protected void txtOK_Click(object sender, EventArgs e)
        {
            Int32 a = Convert.ToInt32(txtA.Text);
            Int32 b = Convert.ToInt32(txtB.Text);
            switch (ddlOperation.SelectedValue)
            {
                case "&":
                    lblC.Text = Convert.ToString(a & b);
                    break;
                case "|":
                    lblC.Text = Convert.ToString(a | b);
                    break;
                case "^":
                    lblC.Text = Convert.ToString(a ^ b);
                    break;
                case "~":
                    //lblC.Text = Convert.ToString(a ~ b);
                    break;
            }
        }

        protected void btnUpload_Click(object sender, EventArgs e)
        {
            byte[] abc = fuAttack.FileBytes;
            lblInfo.Text = abc.Length.ToString();

            System.IO.Stream myStream = fuAttack.FileContent;
            lblInfo.Text = lblInfo.Text + "<br>" + myStream.Length.ToString();
        }

        public void BindUrl()
        {
            //List<URLRewriterEO> lstMapUrlTemp = new List<URLRewriterEO>();
            //foreach (var item in System.Web.Routing.RouteTable.Routes)
            //{
            //    lstMapUrlTemp.Add(new URLRewriterEO() { routeName = item.ToString(), routeUrl = "", physicalFile = "" });
            //}
            //grvList.DataSource = lstMapUrlTemp.ToList();
            //grvList.DataBind();
        }

        protected void btnSQLite_Click(object sender, EventArgs e)
        {
            //try
            //{
            //    DB_SQLite_EXT dbSQLite = new DB_SQLite_EXT();
            //    lblSQLite.Text = "[" + dbSQLite.getNewUrl(txtSQLite.Text) + "]";
            //}
            //catch (Exception ex)
            //{
            //    lblSQLite.Text = ex.ToString();
            //}
        }
    }
}